/* ----------------------------------------------------------------------------
* File: command_handler_impl.h
*
* Desc: Implementation of command event handler for Skype API
*
* Created: 29/06/2011, by Alexey Korshunov
* ---------------------------------------------------------------------------- */
#ifndef _COMMAND_HANDLER_IMPL_H_
#define _COMMAND_HANDLER_IMPL_H_

#include <list>
#include <memory>

#include "api_command_dispatcher.h"
#include "base_module.h"
#include "debug_logger.h"
#include "exception.h"
#include "module_controller.h"
#include "quiz_module.h"

#define IID_SERVICE_EVENT_HANDLER		1

namespace SkypePlugin
{
	struct APICommandHandlerParams
	{
		APICommandHandlerParams() 
			: Controller(NULL)
			, ServiceHandle(NULL)
		{
		}

		ModuleManagement::ModuleController* Controller;		// module controller
		SERVICE_STATUS_HANDLE ServiceHandle;
	};
	
	class APICommandHandlerImpl 
		: public SkypeProtection::APICommandHandler
	{
	public:
		APICommandHandlerImpl();
		~APICommandHandlerImpl();

		void Init(const APICommandHandlerParams& params) throw(Common::Exception);

		// APICommandHandler implementation
		virtual void OnMessageStatus(SKYPE4COMLib::IChatMessage* pMessage, SKYPE4COMLib::TChatMessageStatus Status);

	private:
		void CheckParams(const APICommandHandlerParams& params)
			throw (Common::Exception);
		QuizCore::QuizModule* FindQuizModule(const std::string& ChatName);
		Common::Error CheckControlCommand(SKYPE4COMLib::IChatMessage* pMessage);
		Common::Error ProcessQuizCommand(const std::list<std::string>& words, const std::string& ChatName);
		Common::Error ProcessTalkCommand(const std::list<std::string>& words, const std::string& ChatName);
		Common::Error ProcessWeatherCommand(const std::list<std::string>& words, const std::string& ChatName);

		Common::Error StartQuiz(const std::string& ChatName) throw(Common::Exception);
		Common::Error StopQuiz(const std::string& ChatName) throw(Common::Exception);
		Common::Error StatisticQuiz(const std::string& ChatName) throw(Common::Exception);
		Common::Error UserStatisticQuiz(const std::string& ChatName) throw(Common::Exception);
		Common::Error PromptQuiz(const std::string& ChatName);
		Common::Error NextQuestionQuiz(const std::string& ChatName) throw(Common::Exception);

		void StartTalkModule() {}
		void StopTalkModule() {}

		void StartWeatherModule() {}
		void StopWeatherModule() {}

		bool IsQuizModule(ModuleManagement::BaseModule* module);

		APICommandHandlerParams m_Params;
		std::auto_ptr<Common::Logger> m_Logger; 
	};

	std::auto_ptr<SkypeProtection::APICommandHandler> CreateSkypeServiceEventHandler(const APICommandHandlerParams& params);
}

#endif // _COMMAND_HANDLER_IMPL_H_